<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{padding:10px;margin:10px;border:solid 1px black;}

        .red{background:red}
        .green{border: solid 10px green;}
    </style>
</head>
<body>
    <div class="app">
        <h1>这是 - {{title}}</h1>
        <p>父组件的数据为：{{msg}}</p>

        <Child1 ref="c" abc="hello" class="red" @click="fn" style="width:100px;"></Child1>
    </div>
</body>
<template id="child1Temp">
    <div class="green" @click="fn" style="height:100px;">
        <h3>这是 - {{title}}</h3>
        <p>子组件的数据为：{{msg}}</p>
    </div>
</template>
<script src="../vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data(){
            return {
                title: "根组件",
                msg:"父组件的数据"
            }
        },
        methods:{
            fn(){
                console.log("1");
            }
        },
        components:{
            Child1: {
                data(){
                    return {
                        title:"子组件1",
                        msg: "子组件的数据"
                    }
                },
                template: "#child1Temp",
                methods:{
                    fn(){
                        console.log("2");
                    }
                },
                props:["abc"]
            }
        }
    })

    app.mount(".app");

</script>
</html>